/*
 * WorkManagerBean.java
 *
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.mikrotubula.managers;

import info.mikrotubula.db.Users;
import info.mikrotubula.db.Works;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Krystian
 */
@Stateless
public class WorkManagerBean implements WorkManagerLocal {
    
    @PersistenceContext(unitName = "persistence")
    protected EntityManager em;
    
    /** Creates a new instance of WorkManagerBean */
    public WorkManagerBean() {
    }
    
    public Works create(String workName, String workDescription, Date workDate, Users user) {
        Works work = new Works(workName,workDescription, workDate, user);
        em.persist(work);
        return work;
    }
    
    @SuppressWarnings("unchecked")
    public List<Works> getWorks() {
        return (List<Works>) em.createNamedQuery("Works.findAll").getResultList();
    }  
    
    public void remove(Works work) {
        em.remove(work);
    }
    
}
